<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class Linkslistsstatistic extends Model
{
    protected $table = 'links_lists_statistic';
    protected $primaryKey = 'id';

    public static function gettLinksListsStatistic($links_id,$phase)
    {
        return self::select("id")->where("links_id",$links_id)->where("phase",$phase)->first();
    }

    public static function creatLinksListsStatistic($info)
    {
        return self::insert($info);
    }

    public static function getLinksListsStatistics($links_id,$phase)
    {
        $query = self::select("links_lists_statistic.*","links_lists.title","links_lists.users_id","links_lists.platfrom_type","links_lists.original_id","links_lists.limit_pv")->leftJoin('links_lists', 'links_lists_statistic.links_id', '=', 'links_lists.links_id');
        if (!empty($links_id)) $query->where("links_lists_statistic.links_id",$links_id);
        if (!empty($phase)) $query->where("links_lists_statistic.phase",$phase);
        return $query->orderBy("links_lists.id","DESC")->paginate(25);
    }

    public static function getLinksListsOldStatistics($links_id)
    {
        return DB::select('select sum(page_view) as page_view,sum(mini_view) as mini_view,sum(mini_activate) as mini_activate from links_lists_statistic where links_id = :links_id', ['links_id' => $links_id]);
    }

    public static function getDailyLinksListsStatistics($links_id,$phases)
    {
        return self::where("links_id",$links_id)->whereIn("phase",$phases)->orderBy("id","DESC")->take(30)->get();
    }

}
